<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import {
  Menu as IconMenu,
  House,
  User,
  UserFilled,
  FirstAidKit,
  Calendar,
  Bowl,
  Tools
} from '@element-plus/icons-vue'

const isCollapse = ref(false)
const router = useRouter()

const handleSelect = (key: string) => {
  router.push(key)
}
</script>

<template>
  <el-container class="layout-container">
    <el-aside :width="isCollapse ? '64px' : '240px'" class="sidebar">
      <el-menu
        default-active="/dashboard"
        class="el-menu-vertical"
        :collapse="isCollapse"
        @select="handleSelect"
      >
        <div class="logo-container">
          <img src="/vite.svg" alt="Logo" class="logo" v-if="!isCollapse" />
        </div>
        <el-menu-item index="/dashboard">
          <el-icon><House /></el-icon>
          <span>仪表盘</span>
        </el-menu-item>
        <el-menu-item index="/residents">
          <el-icon><User /></el-icon>
          <span>住户管理</span>
        </el-menu-item>
        <el-menu-item index="/staff">
          <el-icon><UserFilled /></el-icon>
          <span>员工管理</span>
        </el-menu-item>
        <el-menu-item index="/medical">
          <el-icon><FirstAidKit /></el-icon>
          <span>医疗护理</span>
        </el-menu-item>
        <el-menu-item index="/activities">
          <el-icon><Calendar /></el-icon>
          <span>活动安排</span>
        </el-menu-item>
        <el-menu-item index="/dining">
          <el-icon><Bowl /></el-icon>
          <span>餐饮管理</span>
        </el-menu-item>
        <el-menu-item index="/facility">
          <el-icon><Tools /></el-icon>
          <span>设施维护</span>
        </el-menu-item>
      </el-menu>
    </el-aside>
    <el-container class="main-container">
      <el-header class="header">
        <div class="header-content">
          <el-button 
            class="collapse-btn"
            @click="isCollapse = !isCollapse"
            :icon="IconMenu"
            circle
          />
          <h2 class="page-title">智能养老院管理系统</h2>
        </div>
      </el-header>
      <el-main class="main-content">
        <router-view v-slot="{ Component }">
          <transition name="fade" mode="out-in">
            <component :is="Component" />
          </transition>
        </router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<style scoped lang="scss">
.layout-container {
  height: 100vh;
}

.sidebar {
  transition: var(--transition);
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid rgba(0, 0, 0, 0.1);
}

.logo-container {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  
  .logo {
    height: 32px;
  }
}

.header {
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  height: 100%;
  display: flex;
  align-items: center;
  gap: 20px;
}

.collapse-btn {
  background: transparent;
  border: none;
  font-size: 20px;
  
  &:hover {
    background: rgba(0, 0, 0, 0.05);
  }
}

.page-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-color);
  margin: 0;
}

.main-content {
  padding: 32px;
  background: var(--background-color);
}

.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

:deep(.el-menu-item) {
  height: 50px;
  line-height: 50px;
  margin: 8px;
  border-radius: 8px;
  
  &:hover {
    background: rgba(0, 0, 0, 0.05);
  }
  
  &.is-active {
    background: var(--primary-color);
    color: white;
  }
}
</style>